package cn.codeforfun;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * Created by Administrator on 2017/2/24.
 */
@SpringBootApplication
@MapperScan(basePackages = "cn.codeforfun.mapper")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }


    @Value("${spring.datasource.driver-class-name}")
    private String driverClass;
    @Value("${spring.datasource.url}")
    private String url;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;

    @Bean
    public DataSource dataSource() {
        return DataSourceBuilder.create(Thread.currentThread().getContextClassLoader())
                .driverClassName(driverClass).url(url).username(username).password(password).build();
    }
}
